﻿
Imports Cls_Common
Imports VSModel
Imports System.Data
Partial Class FrontEnd_Control_Sitemap
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            hidCatId.Value = Page.RouteData.Values("Id")
            BindMenu()
        End If
    End Sub
    Protected Sub BindMenu()
        Using Data As New VSEntities
            Dim p = (From q In Data.Menus Where q.ParentId = 0 And q.MenuPosition = 1 Select q Order By q.Sort).ToList
            With rptMenu
                .DataSource = p
                .DataBind()
            End With
        End Using
    End Sub

    Protected Sub rptMenu_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptMenu.ItemDataBound
        Dim row As VSModel.Menu = CType(e.Item.DataItem, VSModel.Menu)
        Dim hplTitle As HyperLink = CType(e.Item.FindControl("hplTitle"), HyperLink)
        hplTitle.Text = row.Title
        hplTitle.NavigateUrl = MainDomain & row.QueryString & "-" & row.MenuId & ".html"

        Dim rptSubCat As Repeater = CType(e.Item.FindControl("rptSubCat"), Repeater)

        Using Data As New VSEntities
            'Lay toan bo cap con cua Cate

            Dim p = (From q In Data.Menus Where q.ParentId = row.MenuId).ToList
            rptSubCat.DataSource = p
            rptSubCat.DataBind()

        End Using
    End Sub
    Protected Sub rptSubCat_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs)
        Dim row As VSModel.Menu = CType(e.Item.DataItem, VSModel.Menu)
        Dim hplSubTitle As HyperLink = CType(e.Item.FindControl("hplSubTitle"), HyperLink)
        hplSubTitle.Text = row.Title
        hplSubTitle.Style.Add("color", "#000000")
        hplSubTitle.NavigateUrl = MainDomain & row.QueryString & "-" & row.MenuId & ".html"
    End Sub
End Class
